// frozennpc.txt
//	Like basicnpc, but this creature stands immboile until either it is attacked
//  or a SDF is non-zero. Then it turns hostile and goes nuts.
// Memory Cells:
//   Cell 0 - If , normally stands still once active. if 1, hunts party
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//   Cell 3,4 - Stuff done flag. Determines whether active or not.
//   Cell 5 - Type of hostility. If 0, set hostility to 11. otherwise, 10.
begincreaturescript;

variables;

short i,target;
short i_am_active = 0;
short hostility_type = 10;
short i_was_attacked = 0;

body;

beginstate INIT_STATE;
	if (get_memory_cell(5) == 0)
		hostility_type = 11;
		
	if (get_flag(get_memory_cell(3),get_memory_cell(4)) > 0) {
		set_attitude(ME,hostility_type);
		i_am_active = 1;
		}
		else {
			set_walk_speed(ME,0);
			set_attitude(ME,4);
			}
	break;

beginstate DEAD_STATE;
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
break;

beginstate START_STATE; 
	if (get_flag(get_memory_cell(3),get_memory_cell(4)) > 0) {
		set_walk_speed(ME,24);
		set_attitude(ME,hostility_type);
		i_am_active = 1;
		}
		else if (i_was_attacked == 0) {
			set_walk_speed(ME,0);
			set_attitude(ME,4);
			i_am_active = 0;
			}
		
	// if I have a target for some reason, go attack it
	if ((i_am_active > 0) && (target_ok())) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_foe_target(ME,-1);
		}
	
	if ((i_am_active > 0) && (get_foe_target(ME,8,0))) {
		do_attack();
		set_state(3);
		}
	if (who_shot_me() >= 0) {
		i_was_attacked = 1;
		set_walk_speed(ME,24);
		set_attitude(ME,hostility_type);
		i_am_active = 1;
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}
	if (my_dist_from_start() >= 6) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}

	if ((i_am_active > 0) && (get_attitude(ME) >= 10) && (get_memory_cell(0) > 0)) {
		set_foe_target(ME,1000);
		set_state(3);
		}

	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	print_str("Talking: It is frozen in place. It can't respond.");
break;